package com.taoz.rpc.core.bootstrap;

import com.taoz.rpc.core.config.ApplicationConfig;
import com.taoz.rpc.core.model.LocalServiceInfo;
import com.taoz.rpc.core.model.ServiceMetaInfo;
import com.taoz.rpc.core.registry.LocalRegistry;
import com.taoz.rpc.core.registry.Registry;
import com.taoz.rpc.core.registry.RegistryFactory;
import com.taoz.rpc.core.server.tcp.VertxTcpServer;

import java.util.List;

public class ServerBootstrap {
    public static void init(List<LocalServiceInfo> localServiceInfoList) throws Exception {
        Registry registry = RegistryFactory.getRegistry();
        registry.init();
        for (LocalServiceInfo info : localServiceInfoList) {
            LocalRegistry.register(info.getServiceInterfaceName(), info.getServiceImplClass());
            registry.register(ServiceMetaInfo.getInstanceByName(info.getServiceInterfaceName()));
        }
        VertxTcpServer server = new VertxTcpServer();
        server.start(ApplicationConfig.getConfig().getServerPort());
    }
}
